
package com.jf.cloud.platform.service.impl;

import com.jf.cloud.common.cache.constant.PlatformCacheNames;
import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.util.PageUtil;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.platform.dto.WebConfigDTO;
import com.jf.cloud.platform.mapper.WebConfigMapper;
import com.jf.cloud.platform.model.WebConfig;
import com.jf.cloud.platform.service.WebConfigService;
import com.jf.cloud.platform.vo.WebConfigVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * 网站配置信息表
 *
 * @author zz
 * @date 2022-08-01 15:53:50
 */
@Service
public class WebConfigServiceImpl implements WebConfigService {

    @Autowired
    private WebConfigMapper webConfigMapper;

    @Override
    public PageVO<WebConfig> page(PageDTO pageDTO, WebConfigDTO webConfigDTO) {
        return PageUtil.doPage(pageDTO, () -> webConfigMapper.list(webConfigDTO));
    }

    @Override
    public WebConfig getById(Long id) {
        return webConfigMapper.getById(id);
    }

    @Override
    public void save(WebConfig webConfig) {
        webConfigMapper.save(webConfig);
    }

    @Override
    public void update(WebConfig webConfig) {
        webConfigMapper.update(webConfig);
    }

    @Override
    public void deleteById(Long id) {
        webConfigMapper.deleteById(id);
    }

    @Override
    public void updateActivityState(Integer configType) {
        webConfigMapper.updateActivityState(configType);
    }

    @Override
    @Cacheable(cacheNames = PlatformCacheNames.WEB_CONFIG_ACTIVITY, key = "#configType")
    public WebConfigVO getActivityWebConfig(Integer configType) {
        return webConfigMapper.getByType(configType);
    }

    @Override
    @CacheEvict(cacheNames = PlatformCacheNames.WEB_CONFIG_ACTIVITY, key = "#configType")
    public void removeActivityWebConfig(Integer configType) {}

    @Override
    public int countByType(Integer configType) {
        return webConfigMapper.countByType(configType);
    }

    @Override
    public WebConfigVO getByConfigType(Integer configType) {
        return webConfigMapper.getByType(configType);
    }
}
